<template>
  <a-modal :open="open" width="1100px" title="出入库明细" centered @ok="onOk" @cancel="onCancel">
    <SearchContainer @search="queryList" @reset="() => formRef.resetFields()">
      <a-form :model="formState" name="validate_other">
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item name="stdate" label="日期范围">
              <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item name="czck" label="操作仓库">
              <SelectWarehouse v-model:value="formState.czck" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </SearchContainer>
    <BaseTable :loading="loading" column-code="00001029" :data-source="tableData" bordered fill>
      <template #bodyCell="{ column }">
        <template v-if="column.dataIndex === 'xh'">
          <div>{{ tableData.length }}</div>
        </template>
      </template>
    </BaseTable>
  </a-modal>
</template>
<script setup>
import { ref } from 'vue'
import { message } from 'ant-design-vue'
import dayjs from 'dayjs'
import { post } from '@/utils/request'
import SearchContainer from '@/components/SearchContainer'
import BaseTable from '@/components/BaseTable'
import SelectWarehouse from '@/components/SelectWarehouse'

const loading = ref(false)
const tableData = ref([
  {
    czsj: '2023-08-02',
    lsh: '10086',
    ckmc: 'gg',
    djlb: '',
    name: '',
    gg: '',
    sl: '',
    dw: '',
    yxq: '',
    ph: ''
  }
])

const emit = defineEmits(['update:open', 'success'])
defineProps({
  open: {
    type: Boolean,
    default: false
  },
  rowData: {
    type: Object,
    default: () => ({})
  }
})

const formState = ref({
  dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
})

const onOk = async () => {
  const res = await post('/common/patient/savePatientInfo', formState.value)
  if (res.code === 0) {
    message.success('保存成功')
    emit('success')
  } else {
    message.error(res.msg || '保存失败')
  }
}

const onCancel = () => {
  emit('update:open', false)
}
</script>
